package com.sdp.wz.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.exception.ApplicationException;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.right.excel.importExcel.ImportExcelCallbackService;
import com.sdp.wz.db.wz_inventory_detail.entity.WzInventoryDetail;
import com.sdp.wz.db.wz_inventory_detail.service.IWzInventoryDetailService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2024-07-29
 */
@RestController
@RequestMapping("/WzInventoryDetailController")
public class WzInventoryDetailController implements ImportExcelCallbackService{
	
	@Autowired
	private Query query;
	
	@Autowired
	private IWzInventoryDetailService iWzInventoryDetailService;
	
	@PostMapping(value = "/page")
	public Result<?> page(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.page(iWzInventoryDetailService, WzInventoryDetail.class, dataCenter));
	}

	@PostMapping(value = "/list")
	public Result<?> list(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.list(iWzInventoryDetailService, WzInventoryDetail.class, dataCenter));
	}

	
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		String imoprtParameter = request.getParameter("imoprtParameter");
		if(StringUtils.isEmpty(imoprtParameter)) {
			throw new ApplicationException("盘存单信息不存在");
		}
		String inventoryId = JSON.parseObject(imoprtParameter).getString("inventoryId");
		if(StringUtils.isEmpty(inventoryId)) {
			throw new ApplicationException("盘存单信息不存在");
		}
		iWzInventoryDetailService.removeWzInventoryDetailByInventoryId(inventoryId);
		
	}

}

